<?php
namespace app\handler\wechat\ai;

use app\services\tools\WechatService;

trait BaseMessageHandler
{
    protected $config;

    public function __construct($config)
    {
        $this->config = $config;
    }

    /**
     * 预留media接口时要用到wechat实例来处理
     * 一般扔给队列去执行客服消息发送
     * @return mixed
     */
    public function getApp()
    {
        $wechat = WechatService::getInstance($this->config);
        return $wechat->getWechat();
    }

    public function getMediaPath($fileName, $event_type = 'image', $ext = 'png')
    {
        $path = app()->getRootPath() . 'public/upload' . DIRECTORY_SEPARATOR . date('Ymd') . DIRECTORY_SEPARATOR . $event_type;
        if (! file_exists($path)) {
            mkdir($path, 0755, true);
        }
        return $path . DIRECTORY_SEPARATOR . $fileName . uniqid() . '.' . $ext;
    }
}